<template>
  <div>
    <input v-model="val" @keyup.enter="enter" type="text">

    <!--  -->
    <!-- <div>
        <input v-model="obj.name" type="text">
        <p>
            {{ obj.name }}
        </p>
    </div>

     <div>
        <input v-model="obj.age" type="text">
        <p>
            {{ obj.age }}
        </p>
    </div> -->
  </div>
</template>

<script>

export default {
    data() {
        return {
            val: "",
            // obj: {
            //     name: "张三"
            // }
        }
    },
    created() {
        // this.obj.age = 20
        // this.$set(目标对象, key, value)
        // console.log(this.obj)
    },
    methods: {
        enter() {
            let obj = {
                id: String(Math.random()).slice(5, 9),
                name: this.val,
                time: Date.now()
            }
            this.$bus.$emit("sendObj", obj)
            this.val = ""
        }
    }
}
</script>

<style>

</style>